package Array;

public class item34 {
}
class Solution {
    public static int[] searchRange(int[] nums, int target) {

    int start = 0;
    int end = nums.length-1;
    int [] res = new int[2];
    boolean flag = false;
    while (start<=end)
    {
        int mid = (start+end)/2;
        if(nums[mid]==target)
        {
            flag = true;
            break;
        }
        if(nums[mid]<target)
        {
            start = mid+1;
        }
        if(nums[mid]>target)
        {
            end = mid-1;
        }
    }
    if(flag==false) {
        res[0] = -1;
        res[1] = 1;
    } else {
        int left=start,right=end;
        while (left<=right)
        {
            while (nums[left]!=target)
                left++;
            while (nums[right]!=target)
                right--;
           break;
        }
        res[0] =left;
        res[1] =right;

    }
    return res;
    }

    public static void main(String[] args) {
        int[] nums = {2,2};
        searchRange(nums,2);
    }
}